﻿using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;

namespace Customs.Components.SLXNK
{
	public class LoaiHinhPhiMauDich
	{
		public static DataTable SelectAll()
		{
			string connectionString = ConfigurationManager.AppSettings["SLXNKConnectionString"];
			string query;
			query = "SELECT Ma_LH AS Ma, Ten_LH AS Ten, Ten_VT FROM SLHINHPMD";
			DataTable dt = SqlHelper.ExecuteDataset(connectionString, CommandType.Text, query).Tables[0];
			foreach (DataRow r in dt.Rows)
			{
				r["Ten"] = FontConverter.TCVN2Unicode(r["Ten"].ToString());
			}

			DataRow row = dt.NewRow();
			row["Ma"] = "   ";
			row["Ten"] = "[Tất cả]";
			row["Ten_VT"] = "";
			dt.Rows.Add(row);
			return dt;
		}				
		
		public static string GetTenVietTat(string maLoaiHinh)
		{
			string connectionString = ConfigurationManager.AppSettings["SLXNKConnectionString"];
			string query;
			query = "SELECT Ma_LH AS Ma, Ten_LH AS Ten, Ten_VT FROM SLHINHPMD WHERE MA_LH = @MaLoaiHinh";	
			SqlParameter[] parameters = new SqlParameter[1];
			parameters[0] = new SqlParameter("@MaLoaiHinh", SqlDbType.Char, 5);
			parameters[0].Value = maLoaiHinh;
			SqlDataReader reader = SqlHelper.ExecuteReader(connectionString, CommandType.Text, query, parameters);
			if (reader.Read())
			{
				return FontConverter.TCVN2Unicode(reader["Ten"].ToString());
			}
			return maLoaiHinh;
		}
		public static string GetTenLoaiHinh(string maLoaiHinh)
		{
			string connectionString = ConfigurationManager.AppSettings["SLXNKConnectionString"];
			string query;
			query = "SELECT Ma_LH AS Ma, Ten_LH AS Ten, Ten_VT FROM SLHINHPMD WHERE MA_LH = @MaLoaiHinh";	
			SqlParameter[] parameters = new SqlParameter[1];
			parameters[0] = new SqlParameter("@MaLoaiHinh", SqlDbType.Char, 5);
			parameters[0].Value = maLoaiHinh;
			SqlDataReader reader = SqlHelper.ExecuteReader(connectionString, CommandType.Text, query, parameters);
			if (reader.Read())
			{
				return FontConverter.TCVN2Unicode(reader["Ten"].ToString());
			}
			return maLoaiHinh;
		}
		
	}
}
